import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DeviceVO, DeviceForm, DeviceQuery } from '@/api/primary/device/types';

/**
 * 查询设备列表
 * @param query
 * @returns {*}
 */

export const listDevice = (query?: DeviceQuery): AxiosPromise<DeviceVO[]> => {
  return request({
    url: '/primary/device/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询设备详细
 * @param id
 */
export const getDevice = (id: string | number): AxiosPromise<DeviceVO> => {
  return request({
    url: '/primary/device/' + id,
    method: 'get'
  });
};

/**
 * 查询设备详细
 * @param id
 */
export const qing = (id: string | number): AxiosPromise<DeviceVO> => {
  return request({
    url: '/primary/device/delete_all/' + id,
    method: 'get'
  });
};

/**
 * 开闸
 * @param id
 */
export const kaizha = (id: string | number): AxiosPromise<DeviceVO> => {
  return request({
    url: '/primary/device/manualOpenDoor/' + id,
    method: 'get'
  });
};
/**
 * 开启相机识别
 * @param id
 */
export const Camera = (id: string | number): AxiosPromise<DeviceVO> => {
  return request({
    url: '/primary/openTurnOff/' + id,
    method: 'get'
  });
};
/**
 * 新增设备
 * @param data
 */
export const addDevice = (data: DeviceForm) => {
  return request({
    url: '/primary/device/binding',
    method: 'post',
    data: data
  });
};

/**
 * 修改设备
 * @param data
 */
export const updateDevice = (data: DeviceForm) => {
  return request({
    url: '/primary/device',
    method: 'put',
    data: data
  });
};
/**
 * 重新下发
 * @param data
 */
export const DevicePushAll = (data: any) => {
  return request({
    url: '/primary/member/rePushAll',
    method: 'put',
    data: data
  });
};

/**
 * 删除设备
 * @param id
 */
export const delDevice = (id: string | number | Array<string | number>) => {
  return request({
    url: '/primary/device/unbinding/' + id,
    method: 'get'
  });
};
